package cyb.test;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class test {
    public static void main(String[] args) {
        BitSet bitSet = new BitSet();
        bitSet.set(11);
        bitSet.set(2);
        bitSet.set(4);
        bitSet.set(5);
        bitSet.set(9);
        System.out.println(bitSet);
    }

    public static void intersect1(String s1, String s2) {
        List<String> collect1 = Stream.of(s2.split(",")).collect(Collectors.toList());
        List<String> collect2 = Stream.of(s1.split(",")).collect(Collectors.toList());
        collect1.retainAll(collect2);
        System.out.println("交集1：" + collect1);
    }

    public static void intersect3(String s1, String s2) {
        String[] split1 = s1.split(",");
        String[] split2 = s2.split(",");

        java.util.ArrayList<String> list1 = new ArrayList<>(split1.length);
        java.util.ArrayList<String> list2 = new ArrayList<>(split1.length);
        Collections.addAll(list1, split1);
        Collections.addAll(list2, split2);
        list1.retainAll(list2);
        System.out.println("交集3：" + list1);
    }

    public static void intersect2(String s1, String s2) {
        String[] arr1 = s1.split(",");
        String[] arr2 = s2.split(",");
        List<String> l = new LinkedList<String>();
        Set<String> common = new HashSet<String>();
        for (String str : arr1) {
            if (!l.contains(str)) {
                l.add(str);
            }
        }
        for (String str : arr2) {
            if (l.contains(str)) {
                common.add(str);
            }
        }
        System.out.println("交集2：" + common);
    }

    public static void setCompare(Set<String> set1, Set<String> set2) {
        set1.retainAll(set2);
        System.out.println("交集：" + set1);

    }

    public static String longestCommonPrefix(String[] strs) {
        for (int i = 0; ; i++) {
            Character temp = null;
            for (String str : strs) {
                if (str.length() <= i) {
                    return str.substring(0, i);
                }
                if (temp != null && temp != str.charAt(i)) {
                    return str.substring(0, i);
                } else {
                    temp = str.charAt(i);
                }
            }
        }

    }
}
